
<%@page import="cn.jhc.dao.MsgDao"%>
<%@page import="cn.jhc.dao.MusicDAO"%>
<%@page import="cn.jhc.dao.ConnectionFactory"%>
<%@page import="cn.jhc.bean.MsgBean"%>
<%@page import="java.util.ArrayList"%>
<%@page import="cn.jhc.bean.UserBean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="./css/title.css"></link>
<style>
table {
	color: white;
	background-color:rgba(0,0,0,0.25);
	box-shadow:0px 0px 5px 1px black;
	border: 0px solid rgba(0,0,0,0.65);
	margin-top:2px;
	margin-bottom:20px;
}
</style>
<script language="javascript" type="text/javascript">
	function openwin() {
		var iTop=(window.screen.height-400)/2;
		var iLeft=(window.screen.width-400)/2;
		window.open("msgMusic.jsp","",
				"height=400, width=400, top="+iTop+",left="+iLeft+"toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
	}
</script>
<title>留言板</title>
</head>
<body>
	<%
		int CurrentPage = 1;
		int titleCount = 15;
		int intPageCount;
		if (request.getParameter("page") != null)
			CurrentPage = Integer.parseInt(request.getParameter("page"));
		if (CurrentPage < 1)
			CurrentPage = 1;
		int MsgCount;
	%>

	<div id="wrapper">
		<jsp:include page="./header.jsp"></jsp:include>
		<div id="address">
			<a>当前位置： 讨论区 > 乐曲交流区</a>
		</div>
		<div id="wrapperdown">
			<%
				ArrayList<MsgBean> m = new ArrayList<MsgBean>();
				MusicDAO dao = new MusicDAO();
				dao.setCon(ConnectionFactory.getConnection());
				m = dao.getAllMessages(CurrentPage, titleCount);
				request.setAttribute("title", m);
			%>
			<%
				ArrayList<MsgBean> b = new ArrayList<MsgBean>();
				MusicDAO dao3 = new MusicDAO();
				dao3.setCon(ConnectionFactory.getConnection());
				b = dao3.getBetterMessages();
				request.setAttribute("better", b);
			%>
			<%
				ArrayList<MsgBean> t = new ArrayList<MsgBean>();
				MsgDao dao4 = new MsgDao();
				dao4.setCon(ConnectionFactory.getConnection());
				t = dao4.getTopMessages();
				request.setAttribute("top", t);
			%>
			<%
				MusicDAO dao2 = new MusicDAO();
				dao2.setCon(ConnectionFactory.getConnection());
				intPageCount = dao2.getCount(titleCount);
				if (intPageCount == 0) {
					CurrentPage = 1;
					intPageCount = 1;
				} else {
					if (CurrentPage > intPageCount)
						CurrentPage = intPageCount;
				}
			%>
			<div id="right_news">
				<div id="right_top">
					<a>全部主题 | 置顶</a>
					<div class="date">
						<a>时间</a>
					</div>
					<div class="name">
						<a>作者</a>
					</div>
					<div class="msg">
						<a>回复</a>
					</div>
				</div>
				<table width="900" align="left">
					<%
						ArrayList list = (ArrayList) request.getAttribute("top");
							if (list != null) {
								for (int i = 0; i < list.size(); i++) {
									MsgBean top = (MsgBean) list.get(i);
					%>
					<tr>
						<td width="600" height="40"><div id="topTitle">
								[置顶]<a href="showmessages.jsp?id=<%=top.getId()%>"><%=top.getTitle()%></a>
							</div></td>
						<td width="100"><div align="center"><%=top.getDate()%></div></td>
						<td width="100"><div align="center"><%=top.getDisplayname()%></div></td>
						<%
							MsgDao dao5 = new MsgDao();
										dao5.setCon(ConnectionFactory.getConnection());
										MsgCount = dao5.getMsgCount(top.getId());
						%>
						<td><div align="center"><%=MsgCount%></div></td>
					</tr>
					<%
						}
							}
					%>
					<tr>
						<td colspan="4"><div id="better">精华帖</div></td>
					</tr>
					<%
						ArrayList bet = (ArrayList) request.getAttribute("better");
							if (bet != null) {
								for (int i = 0; i < bet.size(); i++) {
									MsgBean bett = (MsgBean) bet.get(i);
					%>
					<tr>
						<td width="70%" height="40" class="underline"><div id="betTitle">
								[精华]<a href="showMusicmessages.jsp?id=<%=bett.getId()%>"><%=bett.getTitle()%></a>
							</div></td>
						<td class="underline"><div align="center"><%=bett.getDate()%></div></td>
						<td class="underline"><div align="center"><%=bett.getDisplayname()%></div></td>
						<%
							MusicDAO dao5 = new MusicDAO();
										dao5.setCon(ConnectionFactory.getConnection());
										MsgCount = dao5.getMsgCount(bett.getId());
						%>
						<td class="underline"><div align="center"><%=MsgCount%></div></td>
					</tr>
					<%
						}
							}
					%>
					<tr>
						<td colspan="4"><div id="better">板块主题</div></td>
					</tr>
					<%
						ArrayList ti = (ArrayList) request.getAttribute("title");
						if (ti != null) {
							for (int i = 0; i < ti.size(); i++) {
								MsgBean tit = (MsgBean) ti.get(i);
					%>
					<tr>
						<td width="70%" height="40" class="underline"><div id="ordTitle">
								[普通]<a href="showMusicmessages.jsp?id=<%=tit.getId()%>"><%=tit.getTitle()%></a>
							</div></td>
						<td class="underline"><div align="center"><%=tit.getDate()%></div></td>
						<td class="underline"><div align="center"><%=tit.getDisplayname()%></div></td>
						<%
							MusicDAO dao5 = new MusicDAO();
									dao5.setCon(ConnectionFactory.getConnection());
									MsgCount = dao5.getMsgCount(tit.getId());
						%>
						<td class="underline"><div align="center"><%=MsgCount%></div></td>
					</tr>
					<%
						}
						}
					%>
				</table>
			</div>
			<%
				UserBean user = (UserBean) session.getAttribute("user");
				if (null == user) {
			%>
			<div id="button">
				<div class="submit"><a href="login.jsp?getb=taolunquMusic.jsp">开启一个新话题</a></div>
			</div>
			<%
				} else {
			%>
			<div id="button">
				<div class="submit"><a href="" onclick="openwin()">开启一个新话题</a></div>
			</div>
			<%
				}
			%>
			<div id="page" align="right">
				<a>第<%=CurrentPage%>页 共<%=intPageCount%>页
				</a> <a href="taolunquMusic.jsp?page=<%=1%>">首页</a>
				<%
					if (CurrentPage > 1) {
				%>
				<a href="taolunquMusic.jsp?page=<%=CurrentPage - 1%>">上一页</a>
				<%
					} else {
				%>
				<a>上一页</a>
				<%
					}
				%>
				<%
					if (CurrentPage >= intPageCount) {
				%>
				<a>下一页</a>
				<%
					} else {
				%>
				<a href="taolunquMusic.jsp?page=<%=CurrentPage + 1%>">下一页</a>
				<%
					}
				%>
				<a href="taolunquMusic.jsp?page=<%=intPageCount%>">末页</a>
			</div>
		</div>
		<div id="button_bg"></div>
		<div id="line2"></div>
		<div id="copyright">
			<a>版权所有:蓝调吉他社 </a><a>| </a>
			<div id="admin">
				<a href="houtai_index.jsp">管理员登录</a>
			</div>
		</div>
	</div>
</body>
</html>